package io.unicorn.modules.water.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import io.unicorn.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.unicorn.modules.water.entity.TDataErrEntity;
import io.unicorn.modules.water.service.TDataErrService;
import io.unicorn.common.utils.PageUtils;
import io.unicorn.common.utils.R;



/**
 * ${comments}
 *
 * @author LNCG
 * @email LNCG@USTL.EDU.CN
 * @date 2021-05-03 08:18:01
 */
@RestController
@RequestMapping("water/tdataerr")
public class TDataErrController {
    @Autowired
    private TDataErrService tDataErrService;

    @RequestMapping("/status")
    //@RequiresPermissions("water:tdataerr:list")
    public List<Map<String,Object>> status(@RequestParam Map<String, Object> params){
        List<Map<String,Object>> page = tDataErrService.queryErrInfo(params);

        //return R.ok().put("page", page);
        return page;
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("water:tdataerr:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tDataErrService.queryPage(params);

        return R.ok().put("page", page);
    }




    /**
     * 信息
     */
    @RequestMapping("/info/{deviceId}")
    @RequiresPermissions("water:tdataerr:info")
    public R info(@PathVariable("deviceId") String deviceId){
        TDataErrEntity tDataErr = tDataErrService.getById(deviceId);

        return R.ok().put("tDataErr", tDataErr);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("water:tdataerr:save")
    public R save(@RequestBody TDataErrEntity tDataErr){
        tDataErrService.save(tDataErr);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("water:tdataerr:update")
    public R update(@RequestBody TDataErrEntity tDataErr){
        ValidatorUtils.validateEntity(tDataErr);
        tDataErrService.updateById(tDataErr);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("water:tdataerr:delete")
    public R delete(@RequestBody String[] deviceIds){
        tDataErrService.removeByIds(Arrays.asList(deviceIds));

        return R.ok();
    }

}
